<template>
	<el-breadcrumb separator="/" class="custom-breadcrumb">
		<el-breadcrumb-item :to="{ path: '/Welcome' }">首页</el-breadcrumb-item>
		<el-breadcrumb-item>公司管理</el-breadcrumb-item>
		
	</el-breadcrumb>


	<!-- 搜索 -->
	<el-form :inline="true" :model="queryInfo" class="search-form">
		<el-form-item label="公司名">
			<el-input v-model="queryInfo.username" placeholder="请输入公司名" clearable style="width: 150px;" />
		</el-form-item>

		<el-form-item label="公司地址">
			<el-input v-model="queryInfo.mobile" placeholder="请输入公司地址" clearable />
		</el-form-item>
		<el-form-item>
			<el-button type="primary" @click="queryDataList">搜索</el-button>
			
		</el-form-item>
	</el-form>


	<!-- 表格 -->
	<el-table :data="dataList" row-key="id" style="width: 100%" @selection-change="handleSelectionChange" border>
		<el-table-column type="selection" width="55" />
		<el-table-column prop="id" label="ID" width="85" />
		<el-table-column prop="companyName" label="公司名称" width="200" />
		<el-table-column prop="companyAddress" label="公司地址" />
		<el-table-column prop="companyPhone" label="公司电话" />
		<el-table-column prop="companyEmail" label="公司邮件" />
		<el-table-column prop="companyIntro" label="公司介绍" />

		

		<el-table-column label="操作" width="200">
			<template #default="scope">
				<el-button type="primary" @click="update(scope.row)">编辑</el-button>
				<el-button type="danger" @click="remove(scope.row.id)">删除</el-button>
			</template>
		</el-table-column>
	</el-table>





	<!-- 修改对话框 -->
	<el-dialog :title="title" v-model="dialogFormVisible" width="950" @close="cancle">
		<el-form :model="counselorData" label-width="100">
			<el-form-item label="公司名">
				<el-input v-model="counselorData.companyName" autocomplete="off" placeholder="请输入公司名"></el-input>
			</el-form-item>
			<el-form-item label="公司地址">
				<el-input v-model="counselorData.companyAddress" autocomplete="off" placeholder="请输入公司地址"></el-input>
			</el-form-item>
			<el-form-item label="公司电话">
				<el-input v-model="counselorData.companyPhone" autocomplete="off" placeholder="请输入公司电话"></el-input>
			</el-form-item>
			<el-form-item label="公司邮件">
				<el-input v-model="counselorData.companyEmail" autocomplete="off" placeholder="请输入公司邮件"></el-input>
			</el-form-item>
			<el-form-item label="公司介绍">
				<el-input v-model="counselorData.companyIntro" autocomplete="off" placeholder="请输入公司介绍"
					show-password></el-input>
			</el-form-item>


		</el-form>
		<template #footer>
			<div class="dialog-footer">
				<el-button @click="cancle">取 消</el-button>
				<el-button type="primary" @click="confirm">
					确 定
				</el-button>
			</div>
		</template>
	</el-dialog>




	<!-- 分页区域 -->
	<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
		:current-page="queryInfo.pageNum" :page-sizes="[5, 10, 15, 20]" :page-size="queryInfo.pageSize"
		layout="total, sizes, prev, pager, next, jumper" :total="total">
	</el-pagination>







</template>

<script setup>
	import {
		ElMessage,
		ElMessageBox,

	} from "element-plus";
	import {
		getCurrentInstance,
		onMounted,
		reactive,
		ref
	} from "vue";


	// 搜索参数
	const queryInfo = reactive({
		username: '',
		id: '',
		companyName: '',
		companyAddress: '',
		companyPhone: '',
		companyEmail: '',
		companyIntro: '',
		del: '',
		pageNum: 1,
		pageSize: 10
	});


	// 总数量
	const total = ref(0)
	// 数据列表
	const dataList = ref([])
	const axios = getCurrentInstance().appContext.config.globalProperties.axios;


	const queryDataList = () => {
		axios.get('company/page?', {
			params: queryInfo,
			// console.log('接口响应数据:', response.data);
		}).then((resp) => {
			if (resp.code == 200) {
				dataList.value = resp.data.list;
				total.value = resp.data.total;
			} else {
				ElMessage.error('查询失败')
			}
		})
	}




	// 编辑权限

	const title = ref("编辑权限")
	const dialogFormVisible = ref(false)
	const counselorData = ref({
		username: '',
		id: '',
		companyName: '',
		companyAddress: '',
		companyPhone: '',
		companyEmail: '',
		companyIntro: '',
		del: '',
		
	})
	// 重置
	const cancle = () => {
		dialogFormVisible.value = false
		// 重置
		counselorData.value = {
		username: '',
		id: '',
		companyName: '',
		companyAddress: '',
		companyPhone: '',
		companyEmail: '',
		companyIntro: '',
		del: '',
		
		}
		console.log('你点击了取消按钮');
	}



	// 编辑公司

	const update = (row) => {

		title.value = "编辑公司"
		dialogFormVisible.value = true
		counselorData.value = row
		
		console.log(row);
	};



	const confirm = () => {
	
			axios.put('company', counselorData.value)
				.then((resp) => {
					if (resp.code == 200) {
						ElMessage.success('修改成功')
					} else {
						ElMessage.error('修改失败')
					}
					queryDataList();
					dialogFormVisible.value = false;
				})
			console.log('你点击了确定按钮');

	

	}



	// 多选
	const multipleSelection = ref([])
	const handleSelectionChange = (val) => {

		multipleSelection.value = val.map(item => {
			return item.id
		})
		console.log(multipleSelection.value);
	}







	const handleSizeChange = (size) => {
		console.log('每页显示数量发生改变');
		queryInfo.pageSize = size
		queryDataList()
	}
	const handleCurrentChange = (num) => {
		console.log('页码发生改变');
		queryInfo.pageNum = num
		queryDataList()
	}



	onMounted(() => {
		queryDataList()
	})
</script>

<style scoped>
	.custom-breadcrumb {
		padding: 12px 16px;
		background-color: #ffffff;
		border-radius: 4px;
		box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.08);
		/* 添加阴影效果 */
	}
</style>